/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2025-08-17
 * Time: 17:41
 */

class Counter2{
    private static int count = 0;

    public void add(){
        synchronized(this){
            count++;
        }
    }

    public int get(){
        return count;
    }
}

public class demo2 {
    public static void main(String[] args) throws InterruptedException {
        Object locker = new Object();
        Counter2 counter2 = new Counter2();
        Thread t1 = new Thread(()-> {
            for (int i = 0; i < 50000; i++) {
                synchronized(locker){
                    counter2.add();
                }
            }
        });
        t1.start();
        t1.join();


        System.out.println("count = " + counter2.get());
    }
}
